<template>
  <div class="app-container">
    <el-row type="flex" align="center" :gutter="20">
      <el-form class="filterData-block" label-position="left" :inline="true" label-width="auto">
        <el-form-item label="姓名:">
          <el-input
            placeholder="姓名"
            v-model="filterData.realName"
            maxlength="20"
            size="small"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="录取状态:">
          <el-cascader
            v-model="filterData.isHire"
            clearable
            placeholder="全部类型"
            :options="option"
            size="small"
            :props="{value:'id',label:'data'}"
            filterDataable
          ></el-cascader>
        </el-form-item>

        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="refreshTable">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-table v-loading="tableConf.loading" :stripe="true" :border="true" :data="tableData">
        <el-table-column align="center" width="50px" prop="id" label="ID"/>
        <el-table-column align="center" label="头像" width="130px">
          <template  slot-scope="{row}">
            <el-image v-if="row.faceUrl"
                      style="width: 100px; height: 100px"
                      :preview-src-list="[row.faceUrl]"
                      :src="row.faceUrl"
            ></el-image>
            <span v-else>未上传</span>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="100px" prop="realName" label="姓名"/>
        <el-table-column align="center" min-width="100px" prop="jobTitle" label="投递岗位"/>
        <el-table-column align="center" min-width="100px" prop="comName" label="投递公司"/>
        <el-table-column align="center" min-width="100px" prop="crtTime" label="投递时间"/>
        <el-table-column align="center" min-width="100px"  label="状态">
          <template slot-scope="{row}">
            <template v-if="row.isHire===1">
              已录取
            </template>
            <template v-else>
              未录取
            </template>
          </template>
        </el-table-column>
        <el-table-column align="center" width="220px" label="操作">
          <template slot-scope="{row}">
            <el-button size="mini" icon="el-icon-s-platform" type="primary" @click="openDetail(row.customerId,1)">查看简历
            </el-button>
            <el-button size="mini" v-if="row.isHire!=1" icon="el-icon-s-platform" type="primary" @click="doHire(row.id)">录用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-pagination
        :page-sizes="tableConf.sizes"
        :page-size="tableConf.size"
        :total="tableConf.total"
        :current-page="tableConf.page"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
    <el-dialog width="50%"  v-if="visible[0]" :visible.sync="visible[0]" title="详情" :close-on-click-modal="false" top="0"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <CustomerDetails ref="detail" :id="detailId" :closeDialog="closeDialog"></CustomerDetails>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" class="primary" @click="visible[0] = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import CustomerDetails from '@/components/Customer/CustomerDetails'
import {getListByIntermediaryApi,doCustomerHireApi} from "@/api/customer";

export default {
  components: { CustomerDetails },
  data() {
    return {
      tableData: [],
      tableConf: {
        page: 1,
        sizes: [10, 20, 50, 100],
        total: 0,
        size: 10,
        loading: false
      },
      option: [
        {id:1,data: '已录取'},
        {id:0,data: '未录取'},
      ],
      visible: {//控制弹窗显示
        0: false
      },
      detailId: null,
      filterData: {
        realName: '',
        isHire: 0
      },
      placeTypeLoading: true,

    }
  },
  mounted() {
    this.getTableList()
  },
  methods: {
    downloadCode(url) {
      window.open(url)
    },

    //打开添加/编辑页
    openDetail(id = null) {
      this.detailId = id
      this.visible[0] = true
    },
    //关闭指定弹窗并刷新页面
    closeDialog(index) {
      this.visible[index] = false
      this.getTableList()
    },
    // 每页显示数量change
    handleSizeChange(e) {
      this.tableConf.size = e
      this.getTableList()
    },
    // 当前页change
    handleCurrentChange(e) {
      this.tableConf.page = e
      this.getTableList()
    },
    //获取列表
    getTableList() {
      this.tableConf.loading = true
      const isHire = this.filterData.isHire.length === 0 ? 0 : this.filterData.isHire[0];
      getListByIntermediaryApi({
        page: this.tableConf.page,
        limit: this.tableConf.size,
        isHire: isHire,
        realName: this.filterData.realName
      }).then((res) => {
        this.tableData = res.list
        this.tableConf.total = res.count
        console.log(this.tableData)
      }).finally(() => {
        this.tableConf.loading = false
      })
    },

    doHire(id)
    {
      this.$confirm('确定录用该求职者吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        doCustomerHireApi({id}).then((res)=>{
          this.$message.success('录用成功');
          this.getTableList()
        })
      })
    },
    refreshTable() {
      this.tableConf.page = 1
      this.getTableList()
    }
  }
}
</script>
<style lang="scss" scoped>
.filterData-block {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
